/*===========================================================
 
 .---=||||[ B L O O D Y ]|||||=====================----------....
 |                                                              |
 |    THE  M O S T   B L O O D Y  GAME EVER!                    |
 |                                                              |
 |    bloody harvest is coming... soon,                         |
 |                                              heil Satan!     |
 !                                                              !
 .                                                              ,
  ~~~~-------------================================|||||||||==-~




 Name-Space: {core, logic, editor}
 Module: {draw, coll, scgr, ...}
 Class: <name of class>
 Last modification:  <author>, <time>

 TODO:
 <-------- todo #1 ---------->
 <-------- todo #2 ---------->
 <-------- todo #3 ---------->
        ............
 <-------- todo #n ---------->

 FIX:
 <-------- fix #1 ----------->
 <-------- fix #1 ----------->
         ..........
 <-------- fix #n ----------->




 
 
 ============================================================*/
#include "core/evnt/EventControl.h"

namespace core
{

	namespace evnt
	{

		EventControl* EventControl::inst = 0;

		EventControl::EventControl()
		{
			keyboard = new Keyboard();
			mouse = new Mouse();
			shouldEnd = false;

		}

		void EventControl::processEvent()
		{
			SDL_Event event;
			while(SDL_PollEvent(&event))
			{
				switch (event.type)
				{
					case SDL_KEYUP:
					case SDL_KEYDOWN:
						keyboard->processEvents(event.key);
						break;
						
					case SDL_MOUSEBUTTONDOWN:
					case SDL_MOUSEBUTTONUP:
						mouse->processButtonEvent(event.button);
						break;
						
					case SDL_MOUSEMOTION:
						//std::cout << "Mouse Motion" << std::endl << std::flush;
						mouse->processMotionEvent(event.motion);
						break;
						
					case SDL_QUIT:
						shouldEnd = true;
						break;
				}
			}
		}

		EventControl::~EventControl()
		{
			delete mouse;
			delete keyboard;
		}

		EventControl& EventControl::instance()
		{
			if (!inst)
			{
				inst = new EventControl();
			}
			return *inst;
		}

		void EventControl::free()
		{
			if (inst)
			{
				delete inst;
			}
		}

	}
}

